<template>
	<view class="bt-box">
		<view style="margin-right: 24rpx; flex-shrink: 0;">

			<!-- <u-icon color="#000" name="guanzhu" :size="48" :label="$t('关注')" label-pos="bottom"></u-icon> -->
			<uni-icons :type="iconType" :color="isSelected ? 'red' : '#000'" @click="toggleSelect" size="16">
				{{$t('关注')}}
			</uni-icons>

		</view>





		<block v-if="releaseType=='goods'">
			<u-button v-if="status!=2" :custom-style="{
				margin:'initial',
		  height: '78rpx',
		 	  width: '483rpx',
			  marginRight:'30rpx',
		  fontSize: '28rpx',
		  background: 'linear-gradient(110deg, #000000 0%, #000000 100%)',
		  borderRadius: '18rpx',
		}" hover-class="none" type="primary" @click="fabua">
				<text>{{ type == 1 ? $t(tg) : $t(jb) }}</text>
			</u-button>
		</block>

		<block v-if="releaseType!='goods'&&type==2">
			<u-button v-if="status!=2" :custom-style="{
				margin:'initial',
		  height: '78rpx',
		  marginRight:'30rpx',
			  width: '483rpx',
		  fontSize: '28rpx',
		  background: 'linear-gradient(110deg, #000000 0%, #000000 100%)',
		  borderRadius: '18rpx',
		}" hover-class="none" type="primary" @click="fabua">
				<text>{{ $t(jb) }}</text>
			</u-button>
		</block>


		<u-button v-if="status!=2" :custom-style="{
			margin:'initial',
		  height: '78rpx',
		  width: '483rpx',
		  fontSize: '28rpx',
		  background: 'linear-gradient(110deg, #FF8C7B 0%, #FFD1A2 100%)',
		  borderRadius: '18rpx',
		}" hover-class="none" type="primary" @click="communicate">{{ $t('即时沟通') }}
		</u-button>




		<!-- && status !='1' -->
		<!-- <u-button v-if="type === 2 && showJoin" :custom-style="{
      height: '78rpx',
      minWidth: '300rpx',
      background: 'linear-gradient(110deg, #DD2910 0%, #F79B29 100%)',
      borderRadius: '26rpx',
    }" hover-class="none" type="primary" @click="partIn">{{ $t('参与竞标') }}
    </u-button> -->

		<vipPopup v-if="vipShow" :show="vipShow" @change="clickVipPopup" />
	</view>
</template>
<script>
	import {
		createC2CConversation
	} from "@/common/public";
	import vipPopup from "@/components/vipPopup/index.vue";
	import app from "@/main";

	export default {
		props: {
			type: {
				type: Number,
				default: 1,
				required: true,
			},
			toMobile: {
				type: String,
				default: '',
				required: false,
			},
			releaseId: {
				type: Number,
				default: 0,
				required: false,
			},
			releaseType: {
				type: String,
				default: '',
				required: false,
			},
			// 0.我发布的 1.我参与的 2.进行中 3.已完成
			status: {
				type: [Number, String],
				default: ''
			}

		},
		data() {
			return {
				lang: getApp().globalData.lang,
				showJoin: true,
				auth: '',

				vipShow: false,
				//后台开关验证 vip权限
				vip: false,

				iconType: 'heart-filled', // 这里使用的是uniapp文档中的一个图标类型
				isSelected: false,
				lx: '',
				tg: '发起求购',
				jb: '参与订单',
			}
		},
		mounted() {
			this.checkShow()
			uni.showLoading({
				title: "Loading...",
				mask: true
			})
			this.getUserAuth() // 获取用户权限
			this.guanzhu()

			this.$u.api.user.appCheck().then(res => {
				this.report = res.report
				this.vip = res.vip
			})

			if (uni.getStorageSync('off') == false) {
				this.tg = '发起求购'
				this.jb = '参与订单'
			} else {
				this.tg = '招标比价'
				this.jb = '参与竞标'
			}

		},
		components: {
			vipPopup
		},
		computed: {},
		methods: {
			toggleSelect() {
				// if (this.type == 1) {
				// 	this.lx = 2
				// } else if (this.type == 2) {
				// 	this.lx = 3
				// }
				this.$u.api.user.tgGuanZhu({
					guanzhu_id: this.releaseId,
					type: this.type,
					release_type: this.releaseType,
				}).then(res => {
					console.log(res);
					if (res == 2) {
						this.isSelected = true;
					} else {
						this.isSelected = false;
					}
				})
				// this.iconType='heart-filled'
			},
			clickVipPopup() {
				this.vipShow = false
			},
			getUserAuth() {
				const that = this
				that.$u.api.user.getUserAuth().then(res => {
					that.auth = res
					uni.hideLoading()
				})
			},
			guanzhu() {
				// if (this.type == 1) {
				// 	this.lx = 2
				// } else if (this.type == 2) {
				// 	this.lx = 3
				// }
				this.$u.api.user.isGuanZhu({
					guanzhu_id: this.releaseId,
					// type: this.lx,
					type: this.type,
					release_type: this.releaseType,
				}).then(res => {
					console.log(res);
					if (res == 2) {
						this.isSelected = true;
					} else {
						this.isSelected = false;
					}
				})
			},
			checkShow() { // 判断是否显示参与竞标按钮
				this.$u.api.order.checkJoinShow({
					release_id: this.releaseId,
					type: this.releaseType,
				}).then(res => {
					if (res) {
						if (res.show === true) {
							this.showJoin = true
						} else {
							this.showJoin = false
						}
					} else {
						this.showJoin = false
					}

				})
			},

			fabua() {
				if (this.type == 1) {
					uni.navigateTo({
						url: "/pages/release/goods/form"
					})
				} else {
					this.partIn()
				}

			},

			communicate() {
				createC2CConversation(this.toMobile, this)

			},
			partIn() {
				var mobile = uni.getStorageSync('mobile');
				if (mobile === this.toMobile) {
					this.$u.toast(app.$i18n.t('不能参与自己'));
					return false
				}
				var that = this
				that.$u.api.user.order_join_day_auth({
					lang: that.lang
				}).then(res => {
					if (res == 1) {
						that.$u.route({
							url: '/pages/order/process/buildOrder',
							params: {
								type: this.releaseType,
								release_id: this.releaseId,
								// current: this.releaseType
							}
						})
					} else {
						if (that.vip) {
							that.vipShow = true
							return
						} else {
							uni.showModal({
								content: that.$t('您的权限不足哦!请联系工作人员!'),
								showCancel: false,
								confirmText: that.$t('是'),
							})
							return false;
						}
						return
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.bt-box {
		padding: 0 38rpx;
		height: 140rpx;
		position: fixed;
		display: flex;
		bottom: 0;
		left: 0;
		width: 100%;
		// display: flex;
		flex-direction: row;
		align-items: center;
		// justify-content: center;
		justify-content: space-between;
		background-color: #FFFFFF;
		border-top: 1px solid #f1f1f1;
		z-index: 99;
	}
</style>